//
//  DocumentationDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/7/2.
//

import SwiftUI

struct DocumentationDemo: View {
    
    // MARK: PROPERTES
    @State var data: [String] = [
        "Apples", "Oranges", "Bananas"
    ]
    @State var showAlert: Bool = false
    
    // MARK: BODY
    
    // Working cope - things to do:
    // 1
    // 2
    
    /*
     Working cope - things to do:
     1
     2
     */
    var body: some View {
        NavigationView { // START: Nav
//            ScrollView {
//                Text("Hello")
//                ForEach(data, id: \.self) { name in
//                    Text(name)
//                        .font(.headline)
//                }
//            }
            foregroundLayer
            .navigationTitle("Documentation Demo")
            .navigationBarItems(trailing: Button("Alert", action: {
                showAlert.toggle()
            })
            )
            .alert(isPresented: $showAlert) {
                getAlert(text: "This is the alert")
            }
        } // END: Nav
    }
    
    
    /// This is foreground layer that holds a SrcollView
    private var foregroundLayer: some View {
        ScrollView {
            Text("Hello")
            ForEach(data, id: \.self) { name in
                Text(name)
                    .font(.headline)
            }
        }
    }
    
    // MARK: FUNCTIONS
    
    
    /// Get an alert with a specified title.
    ///
    /// This function create an return an alert immediately,
    ///  ```
    ///  getAlert(text: "Hi") -> Alert(title: Text("Hi"))
    ///  ```
    ///
    /// - Warning: Display warning
    /// - Parameter text: This is the title for the alert.
    /// - Returns: Ruturn an alert with a title.
    func getAlert(text: String) -> Alert {
        return Alert(title: Text(text))
    }
    
}

#Preview {
    DocumentationDemo()
}
